﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Helper;

namespace Services.BusinessRules
{
    class ValidateEmail : BusinessObject
    {


        string Data;
        string NameEN;
        string NameVN;

        public ValidateEmail(String namevn, string nameen, string data)
        {
            this.Data = data;
            this.NameVN = namevn;
            this.NameEN = nameen;
            AddValidate(Check());
        }


        string Check()
        {
            if (!IsValidEmail(this.Data) && !String.IsNullOrEmpty(this.Data))
            {
                if (ValueDefine.Lang == ValueDefine.Language.VN)
                {
                    return  ErrorCodeVN.NotValidEmail;
                }
                else
                {
                    return NameEN + " " + ErrorCodeEN.NotValidEmail;
                }
            }
            else
            {
                return null;
            }
        }
        bool IsValidEmail(string strIn)
        {
            return Regex.IsMatch(strIn, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
        }
    }
}
